package com.wc.alorithm_blue_bridge._数学知识.约数.混乘数字;

import java.util.Arrays;

/**
 * @Author congge
 * @Date 2024/5/22 14:35
 * @description https://www.lanqiao.cn/problems/17121/learning/?problem_list_id=33&page=1
 */
public class Main {
    static int N = 1000000;
    static int[] num = new int[10];

    public static void main(String[] args) {
        int res = 0;
        for (int i = 1; i <= N; i++) {
            if (check(i)) {
                res++;
//                System.out.println(i);
            }
        }
        System.out.println(res);
    }

    static boolean check(int x) {
        for (int i = 1; i <= x / i; i++) {
            if (x % i == 0) {
                if (check(i, x / i, x)) return true;
            }
        }
        return false;
    }

    static boolean check(int a, int b, int x) {
        Arrays.fill(num, 0);
        while (a > 0) {
            num[a % 10]++;
            a /= 10;
        }
        while (b > 0) {
            num[b % 10]++;
            b /= 10;
        }
        while (x > 0) {
            num[x % 10]--;
            x /= 10;
        }
        for (int i = 0; i < 10; i++) {
            if (num[i] != 0) return false;
        }

        return true;
    }
}
